package com.example.dingzexi_homework1;

import androidx.recyclerview.widget.GridLayoutManager;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class HomeFragment extends Fragment {

    public HomeFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2)); // 设置为每行两个列表项
        String[] items = {"Item 1", "Item 2", "Item 3", "Item 4"}; // 列表项文本
        int[] imageResources = {R.raw.image1, R.raw.image2, R.raw.image3, R.raw.image4}; // 对应的图片资源
        ListAdapter adapter = new ListAdapter(getContext(), items, imageResources);
        recyclerView.setAdapter(adapter);
        return view;
    }
}